import matplotlib.pyplot as plt
import numpy as np
flags = []
tb = []
mhp = []
value = []
Str = ""
file = open("Data.txt" , "r")
readFlag = False
while(True):
    Str = file.readline()
    if(Str == "END_OF_FILE"):
        break
    elif(Str == "END\n"):
        readFlag = False
    elif(readFlag == False):
        Tmp = ""
        for i in range(len(Str) - 1):
            Tmp += Str[i]
        flags.append(Tmp)
        tb.append([])
        mhp.append([])
        value.append([])
        readFlag = True
    else:
        tmp = ""
        arr = []
        for i in range(len(Str) - 1):
            if(Str[i] == ","):
                arr.append(tmp)
                tmp = ""
            else:
                tmp += Str[i]
        arr.append(tmp)
        tb[-1].append(float(arr[0]))
        mhp[-1].append(float(arr[1]))
        value[-1].append(float(arr[2]))
file.close()

address = []
for i in range(len(flags)):
    address.append("plots/"+flags[i]+".jpg")
    
for i in range(len(flags)):
    print(flags[i])
    for j in range(len(tb[i])):
        print(tb[i][j],",",mhp[i][j],",",value[i][j])

file = open("rootPlots.txt" , "w")
for i in range(len(address)):
    file.write(address[i]+"\n")
file.close()


marker_size=30
plt.rcParams.update({
    "text.usetex": True,
    "font.family": "monospace",
    "font.monospace": 'Computer Modern Typewriter'
})
for i in range(len(flags)):
    plt.clf()
    plt.scatter(mhp[i], tb[i], marker_size, value[i] ,cmap = 'jet')
    plt.title(flags[i]+" (pb)")
    plt.xlabel(r'$m_{H^+}(GeV))$')
    plt.ylabel(r'$tan_\beta$')
    cbar= plt.colorbar()
    plt.savefig(address[i] , format = 'jpg' , dpi = 600)
plt.show()







